home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / tstpfl.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  2KB  |  66 lines

  1. Program TstPFL;
  2.  
  3. { Example for the nwLock unit / NwTP 0.6 API. (c) 1993,1995, R.Spronk }
  4.  
  5. { Tests the following nwLock calls: (Physical File Locking)
  6.  
  7.   ClearPhysicalFileSet
  8.   LogPhysicalFile
  9.   LockPhysicalFileSet
  10.   ReleasePhysicalFile
  11. }
  12.  
  13. Uses nwFile,nwLock; { using this unit will automatically set the locmode to 1 }
  14.  
  15. Var FileName:string;
  16.     TimeOutTicks:word;
  17.  
  18. begin
  19. TimeOutTicks:=360; {wait 20 seconds before locking process times out}
  20.  
  21. writeln('TSTLF: Test of logical file locking.');
  22. writeln('       -Make sure the files referenced to in this example exist.');
  23. writeln('       -Start the exe on 2 or more workstations & enjoy the effect.');
  24. writeln;
  25.  
  26. { Put the names of files-to-be-locked in the 'logged file set' }
  27. FileName:='SYS:PUBLIC/SYSCON.EXE';
  28. IF NOT LogPhysicalFile(FileName,LD_LOG,0)
  29.  then writeln('Logfile failed. Error# ',nwLock.result);
  30. { Note: The files specified have to exist, or an error 156 is
  31.         returned. Using EXE files instead of data files can be
  32.         a bit confusing in this example, but at least those
  33.         files are very likely to be there. }
  34. FileName:='SYS:\PUBLIC\PCONSOLE.EXE';
  35. IF NOT LogPhysicalFile(FileName,LD_LOG,0)
  36.  then writeln('Logfile failed. Error# ',nwLock.result);
  37.  { Repeat logging process for other (if needed) }
  38.  
  39.  
  40. { Lock all files that are currently stored in the 'logged file set' }
  41. writeln('Attempting to Lock files.. ');
  42. IF NOT LockPhysicalFileSet(TimeOutTicks)
  43.  then writeln('LockFileSet (after TimeOut=20 sec) failed. Error# ',nwLock.result);
  44.  
  45. if nwlock.result=0 { locking of files was successful }
  46.  then begin
  47.       { ---Update file, change file, etc.--- }
  48.  
  49.       { Readln to simulate update }
  50.       writeln('Now ''processing'' files. Press RETURN to release locks.');
  51.       readln;
  52.  
  53.       { Suppose we're done with the 1st datafile, but still need file #2:
  54.         -unlock 1 single file; keep in log }
  55.       IF NOT ReleasePhysicalFile('SYS:\PUBLIC\SYSCON.EXE')
  56.        then writeln('ReleaseFile Failed. Error# ',nwLock.result);
  57.  
  58.       writeln('Now ''processing'' still locked file');
  59.       end;
  60.  
  61. { unlock all files; clear 'logged file set' }
  62. IF NOT ClearPhysicalFileSet
  63.  then writeln('ClearFileSet Failed. Error# ',nwLock.result);
  64.  
  65. end.
  66.